
import axios from 'axios';
import {Message} from 'element-ui';
import {getCookie} from '@/utils/auth';

const service = axios.create({
    baseURL:process.env.NODE_ENV === 'production'?'/':'/api',
    timeout:5000
})

service.interceptors.request.use(function(config){
    config.headers['token'] = getCookie()
    return config
},function(error){
    Message({
        type:'error',
        message:'网络请求错误',
        duration:2000
    })
    return Promise.reject(error)
})

service.interceptors.response.use(function(response){
    return response.data;
},function(error){
    Message({
        type:'error',
        message:'请求失败',
        duration:2000
    })
    return Promise.reject(error)
})

export default service